import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {ApiProvider} from "../../providers/api/api";
import {Res} from "../../modal/Res";
import {LoginPage} from "../login/login";

/**
 * Generated class for the ForgetPasswordPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-forget-password',
  templateUrl: 'forget-password.html',
})
export class ForgetPasswordPage {
  username="";
  realname="";
  constructor(public navCtrl: NavController, public navParams: NavParams,public http:ApiProvider) {
  }

  ionViewDidLoad() {
    //console.log('ionViewDidLoad ForgetPasswordPage');
  }

  ionViewDidEnter()
  {
  }

  /**
   * 忘记密码：将密码重置为123456
   */
  forgetPassword()
  {
    var myreg =  /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

    if(this.username=="")
    {
      this.http.showToast("邮箱不能为空！","bottom");
    }
    else if(!myreg.test(this.username))
    {
      this.http.showToast("请输入正确的邮箱！","bottom");
    }
    else if(this.realname=="")
    {
      this.http.showToast("真实姓名不能为空！","bottom");
    }
    else
    {
      this.http.post("/userstu/initPass.do",{real_name:this.realname,log_name:this.username}).subscribe((item:Res)=>{
        if(item.Code=="11111111")
          this.http.showToast(item.Message,"bottom");
        else
        {
          this.http.showToast(item.Message,"bottom");
          this.navCtrl.push(LoginPage);
        }
      })
    }
  }
}
